﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data.SqlClient;

namespace NorthwindTwin
{
    class TwinTask
    {

        public static void CreateTwin()
        {
            NorthwindEntities entities = new NorthwindEntities();
            string script = GetScript();
            string twinName = "testdb";
            entities.ExecuteStoreCommand("Create database " + twinName);

            string connectionString = "Server=.\\SQLEXPRESS;" + " Database=" + twinName + "; Integrated Security=true";
            SqlConnection dbCon = new SqlConnection(connectionString);
            dbCon.Open();
            using (dbCon)
            {
                SqlCommand cmd = dbCon.CreateCommand();
                cmd.CommandText = script;
                cmd.ExecuteNonQuery();
            }
            dbCon.Close();
        }

        public static string GetScript()
        {
            NorthwindEntities entities = new NorthwindEntities();

            string script = entities.CreateDatabaseScript();
            return script;
        }

        static void Main(string[] args)
        {
            CreateTwin();
        }
    }
}
